package cn.school.Service;

import cn.school.Dao.Admindao;
import cn.school.Entity.Admin;
import cn.school.Entity.Page;
import cn.school.Util.SessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminService {
    //Service层文件夹
    public Admin admin(String root,String pass){
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return st.admin(root,pass);
        } finally {
            SessionUtil.closeSession(s);
        }
    }
    public int up(Admin admin) {
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return st.up(admin);
        }catch(Exception e){
            return 0;
        } finally {
            SessionUtil.closeSession(s);
        }
    }
    public int count() throws Exception {
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return st.count();
        } finally {
            SessionUtil.closeSession(s);
        }
    }
    public Page<Admin> pageing(int pageNo,int pageSize,String username,String tele) throws Exception {
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return new Page(0,st.count(),st.findfy(pageNo,pageSize,username, tele));
        } finally {
            SessionUtil.closeSession(s);
        }
    }
    public int add(Admin admin) {
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return st.add(admin);
        }catch(Exception e){
            return 0;
        } finally {
            SessionUtil.closeSession(s);
        }
    }
    public int del(long id) {
        SqlSession s = SessionUtil.getSession();
        try {
            Admindao st = s.getMapper(Admindao.class);
            return st.del(id);
        }catch(Exception e){
            return 0;
        } finally {
            SessionUtil.closeSession(s);
        }
    }
}
